﻿using System;

namespace Gert3D
{
  /// <summary>
  /// Point is a simple point in 2D space.
  /// </summary>
  public struct Point2
  {
    public double X;
    public double Y;
    
    /// <summary>
    /// Creates a new Point initializing X and Y with the given values.
    /// </summary>
    /// <param name="x">The X coordinate of the point</param>
    /// <param name="y">The Y coordinate of the point</param>
    public Point2(double x, double y)
    {
      X = x;
      Y = y;
    }
    
    /// <summary>
    /// Calculates the distance between this point and another by using pythogarean theorem.
    /// </summary>
    /// <param name="other">The other point.</param>
    /// <returns>The distance between the two points.</returns>
    public double DistanceTo(Point2 other)
    {
      double a = X - other.X;
      double b = Y - other.Y;
      return Math.Sqrt(a * a + b * b);
    }
    
    /// <summary>
    /// Calculates the distance between two points by using pythogarean theorem.
    /// </summary>
    /// <param name="p1">The first point.</param>
    /// <param name="p2">The second point.</param>
    /// <returns>The distance between the two points.</returns>
    public static double Distance(Point2 p1, Point2 p2)
    {
      double a = p1.X - p2.X;
      double b = p1.Y - p2.Y;
      return Math.Sqrt(a * a + b * b);
    }
    
  }
}
